import VueRouter from 'vue-router';
// import Message from "element-ui/packages/message/src/main";

//这就是路由
let router = new VueRouter({
    routes: [
        {path: '/', redirect: '/index'},
        // {path: '/creaBok', component: () => import('@/mybolgOrover/creaBok')},
        {path: '/index', component: () => import('@/page/index')},
        {path: '/login', component: () => import('@/page/login')},
        {path: '/rigest', component: () => import('@/page/rigest')},
        {path: '/author', component: () => import('@/page/author')},
        {path: '/fuondpassword', component: () => import('@/page/fuondpassword')},
        {path: '/creaArticle', component: () => import('@/page/creaArticle')},
        {path: '/myphote',  component: () => import('@/page/myphote')},
        //vue_exam
        {path: '/moveconten', component:()=>import('@/page/moveconten')},




        {
            path: '/mybolgs',
            name:'文章详情',
            component: () => import('@/page/mybolgs')
        },

        { path: '/myPhote', component: () => import('@/daoHangL/myPhote')},

        {
            path: '/daohang',
            component: () => import('@/daoHangL/daohang'),
            children: [
                {path: '/index', meta: {name: '首页'}, component: () => import('@/page/index')},
            ]
        },


        {
            path: '/onlyone',
            component: () => import('@/page/onlyone'),
            children: [
                {path: '/', redirect: '/info'},
                {path: '/info', component: () => import('@/renaissance/info')},
                {path: '/profi', component: () => import('@/renaissance/profi')},
                {path: '/blogs', component: () => import('@/renaissance/blogs')},
                {path: '/dat', component: () => import('@/renaissance/dat')},
                {path: '/pasw', component: () => import('@/renaissance/pasw')}
            ]
        },
        {
            path: '/article',
            component:()=>import('@/page/article'),
            children: [
                {path: '/', redirect: '/articleled'},
                {path: '/articleled', component: () => import('@/articlePage/articleled')},
                {path: '/classify', component: () => import('@/articlePage/classify')},
                {path: '/label', component: () => import('@/articlePage/label')},
                {path: '/photo', component: () => import('@/articlePage/photo')},
                {path: '/photograph', component: () => import('@/articlePage/photograph')},
            ]
        }

    ],
    mode: 'history'

})
// 不需要登录的页面的路径，如果在这个名单里，就不需要检测TOKEN
let notNeedLogin = ['/login', '/register']
// 每一个路由变化之前，执行内部的代码
router.beforeEach((to, from, next) => {
    // 如果上述名单之中，不包括即将要去的页面，说明需要登录
    if (notNeedLogin.indexOf(to.path) === -1) {
        // 需要登录的页面，又没有TOKEN，说明没有登录，需要去登录页
        if (localStorage.getItem('TOKEN') == null) {
            // // eslint-disable-next-line no-undef
            // Message.warning('请先登录！');
            // // next(路径)表示跳转到该路径，只在这里可以这么写
            // next('/login');
        }
    }
    document.title ='欢迎来到CofiLkin ';
    // next()没有参数，表示放行，去到原来想去的页面
    next();
})

export default router